package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.domain.ZhDeptInfo;
import com.ruoyi.common.service.IZhDeptInfoService;
import com.ruoyi.system.domain.ZhGuide;
import com.ruoyi.system.domain.ZhNotice;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhProblem;
import com.ruoyi.system.service.IZhProblemService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 常见问题 信息操作处理
 *
 * @author ruoyi
 * @date 2019-04-26
 */
@Controller
@RequestMapping("/system/zhProblem")
public class ZhProblemController extends BaseController
{
    private String prefix = "system/zhProblem";

	@Autowired
	private IZhProblemService zhProblemService;

	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

    @RequiresPermissions("system:zhGuide:edit")
    @GetMapping("wangrditor")
    public String wangrditor(
            Integer id,
            Model model) {
        //todo 随便修改id都能进来

        ZhProblem zhProblem = zhProblemService.selectZhProblemById(id);
        model.addAttribute("item" , zhProblem != null ? zhProblem : new ZhGuide());
        return prefix + "/wangrditor";
    }

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhProblem:view")
	@GetMapping()
	public String zhProblem(ZhProblem zhProblem,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhProblem.getParams())));
		return prefix + "/zhProblem";
	}

	/**
	 * 查询常见问题列表
	 */
    @DataScope(tableAlias = "l")
    @RequiresPermissions("system:zhProblem:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ZhProblem zhProblem)
	{
		startPage();
        List<ZhProblem> list = zhProblemService.selectZhProblemList(zhProblem);
		return getDataTable(list);
	}


	/**
	 * 导出常见问题列表
	 */
	@RequiresPermissions("system:zhProblem:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhProblem zhProblem)
    {
    	List<ZhProblem> list = zhProblemService.selectZhProblemList(zhProblem);
        ExcelUtil<ZhProblem> util = new ExcelUtil<ZhProblem>(ZhProblem.class);
        return util.exportExcel(list, "zhProblem");
    }

	/**
	 * 新增常见问题
	 */
    @DataScope(tableAlias = "l")
    @GetMapping("/add")
    @RequiresPermissions("system:zhProblem:add")
    public String add(ZhProblem zhProblem,ModelMap mmap)
	{
        mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhProblem.getParams())));
        return prefix + "/add";
	}

	/**
	 * 新增保存常见问题
	 */
	@RequiresPermissions("system:zhProblem:add")
	@Log(title = "常见问题", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZhProblem zhProblem)
	{
		return toAjax(zhProblemService.insertZhProblem(zhProblem));
	}

	/**
	 * 修改常见问题
	 */
    @DataScope(tableAlias = "l")
    @GetMapping("/edit/{id}")
    @RequiresPermissions("system:zhProblem:edit")
    public String edit(ZhProblem zhProblem,
                       @PathVariable("id") Integer id,
                       ModelMap mmap)
	{
		mmap.put("zhProblem",zhProblemService.selectZhProblemById(id));
        mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhProblem.getParams())));
        return prefix + "/edit";
	}

	/**
	 * 修改保存常见问题
	 */
	@RequiresPermissions("system:zhProblem:edit")
	@Log(title = "常见问题", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZhProblem zhProblem)
	{
		return toAjax(zhProblemService.updateZhProblem(zhProblem));
	}

	/**
	 * 删除常见问题
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhProblem:remove")
	@Log(title = "常见问题", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(ZhProblem zhProblem,String ids)
	{
		return toAjax(zhProblemService.deleteZhProblemByIds(ids));
	}

}
